package com.springmq.mq.thread;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName : ThreadRabbmit
 * @Author : lby
 * @Date: 2021/1/29 15:34
 * @Description : 线程测试-龟兔赛跑问题
 */
@Data
@Slf4j
public class ThreadRabbit implements Runnable {

    /**
     * 赛道长度
     */
    private Integer raceLength=100;

    /**
     * 兔子
     */
    private String rabbit="rabbit";

    /**
     * 乌龟
     */
    private String tortoise="tortoise";
    @Override
    public void run() {
        // 设置乌龟和兔子速度不同
        for (int i = 1; i <=raceLength ; i++) {
            if (i==100){
                log.info("比赛结束，省着是:{}",Thread.currentThread().getName());
            }
            log.info(":{}正在领先,距离终点还有:{}米",Thread.currentThread().getName(),raceLength-i);
        }
    }

    public static void main(String[] args) {
        ThreadRabbit threadRabbit = new ThreadRabbit();
        new Thread(threadRabbit, threadRabbit.rabbit).start();
        new Thread(threadRabbit, threadRabbit.tortoise).start();
    }
}
